package com.ljfiction.book.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.ljfiction.book.Baner.MyshupingBean;
import com.ljfiction.book.MyView.CircularImageView;
import com.ljfiction.book.MyView.SuperButton;
import com.ljfiction.book.R;
import com.ljfiction.book.tools.ScreenUtils;
import com.ljfiction.book.tools.TimeTool;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Android on 2017/10/20.
 */

public class UserShupingAdapter extends BaseAdapter {

    private List<MyshupingBean.DataBean.ListBean> listcomment = new ArrayList<>();
    private Context context;

    public UserShupingAdapter(List<MyshupingBean.DataBean.ListBean> listcomment, Context context) {
        this.listcomment = listcomment;
        this.context = context;
    }

    @Override
    public int getCount() {
        if (listcomment.size() > 2) {
            return 2;
        } else {
            return listcomment.size();
        }
    }

    @Override
    public Object getItem(int position) {
        return listcomment.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.usershuping, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        Glide.with(context).load(listcomment.get(position).getUserHeadPortraitURL()).override(ScreenUtils.getNum(context,52),ScreenUtils.getNum(context,52)).into(viewHolder.myshupingUser);
        viewHolder.myshupingMynameUser.setText(listcomment.get(position).getPseudonym());
        if (listcomment.get(position).getUserSex() == 0) {
            viewHolder.myshupingsexUser.setImageResource(R.mipmap.sex_n);
        } else {
            viewHolder.myshupingsexUser.setImageResource(R.mipmap.sex_v);
        }
        if (listcomment.get(position).getVipGrade() == 0) {
            viewHolder.isvipimageShupingUser.setVisibility(View.INVISIBLE);
        }else {
            viewHolder.isvipimageShupingUser.setVisibility(View.VISIBLE);
        }
        viewHolder.mushupingtimeUser.setText(TimeTool.getTimeAndChange(String.valueOf(listcomment.get(position).getCommentDateTime())));
        viewHolder.shupingdenglimyUser.setText("LV" + String.valueOf(listcomment.get(position).getUserGrade()));
        /*GradientDrawable gd = (GradientDrawable)viewHolder.gradeCommentuser.getBackground();
        gd.setColor(Color.parseColor("#75D5F8"));*/
        viewHolder.shupingbooknameUser.setText("《"+listcomment.get(position).getBookName()+"》");
        viewHolder.contentMyshupingUser.setText(listcomment.get(position).getCommentContext());
        return convertView;
    }

    static class ViewHolder {
        @BindView(R.id.myshuping_user)
        CircularImageView myshupingUser;
        @BindView(R.id.isvipimage_shuping_user)
        ImageView isvipimageShupingUser;
        @BindView(R.id.myshuping_myname_user)
        TextView myshupingMynameUser;
        @BindView(R.id.myshupingsex_user)
        ImageView myshupingsexUser;
        @BindView(R.id.shupingdenglimy_user)
        SuperButton shupingdenglimyUser;
        @BindView(R.id.mushupingtime_user)
        TextView mushupingtimeUser;
        @BindView(R.id.shupingbookname_user)
        TextView shupingbooknameUser;
        @BindView(R.id.content_myshuping_user)
        TextView contentMyshupingUser;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
   /* @Override
    protected void convert(BaseViewHolder helper, MyshupingBean.DataBean.ListBean item) {
        helper.setText(R.id.content_myshuping_user,item.getCommentContext())
                .setText(R.id.myshuping_myname_user,item.getPseudonym())
                .setText(R.id.shupingbookname_user,item.getBookName())
                .setText(R.id.mushupingtime_user, TimeTool.getTime(String.valueOf(item.getCommentDateTime())));
        Glide.with(mContext).load(item.getUserHeadPortraitURL()).into((ImageView) helper.getView(R.id.myshuping_user));
        if (item.getUserSex()==0){
            Glide.with(mContext).load(R.drawable.sex_n).into((ImageView) helper.getView(R.id.myshupingsex_user));
        }else {
            Glide.with(mContext).load(R.drawable.sex_v).into((ImageView) helper.getView(R.id.myshupingsex_user));
        }
        if (item.getVipGrade()>0){
            helper.getView(R.id.isvipimage_shuping).setVisibility(View.VISIBLE);
        }else {
            helper.getView(R.id.isvipimage_shuping).setVisibility(View.GONE);
        }
    }*/

}
